{#**
 * 2007-2020 PrestaShop SA and Contributors
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://www.prestashop.com for more information.
 *
 * @author    PrestaShop SA <contact@prestashop.com>
 * @copyright 2007-2020 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 * International Registered Trademark & Property of PrestaShop SA
 *#}
{% extends '@PrestaShop/Admin/layout.html.twig' %}
{% trans_default_domain "Admin.Advparameters.Feature" %}
{% import '@PrestaShop/Admin/macros.html.twig' as ps %}
{% form_theme form 'PrestaShopBundle:Admin/TwigTemplateForm:prestashop_ui_kit.html.twig' %}

{%
    set smartyForm, debugModeForm, optionalFeaturesForm, combineCompressCacheForm, mediaServersForm, cachingForm, memcacheForm =
    form.smarty, form.debug_mode, form.optional_features, form.ccc, form.media_servers, form.caching, form.add_memcache_server
%}

{% block content %}
  {{ form_start(form, {'attr' : {'class': 'form'} }) }}
  <div class="row justify-content-center">
    {% block perfs_form_smarty_cache %}
      <div class="col-xl-10">
        <div class="card">
          <h3 class="card-header">
            <i class="material-icons">business_center</i> {{ 'Smarty'|trans }}
          </h3>
          <div class="card-block row">
            <div class="card-text">
              {% block perfs_form_smarty_cache_form %}
                {{ form_widget(smartyForm) }}
              {% endblock %}
            </div>
          </div>
          <div class="card-footer">
            <div class="d-flex justify-content-end">
              <button class="btn btn-primary">{{ 'Save'|trans({}, 'Admin.Actions') }}</button>
            </div>
          </div>
        </div>
      </div>
    {% endblock %}

    {% block perfs_form_debug_mode %}
      <div class="col-xl-10">
        <div class="card">
          <h3 class="card-header">
            <i class="material-icons">bug_report</i> {{ 'Debug mode'|trans }}
          </h3>
          <div class="card-block row">
            <div class="card-text">
              {% block perfs_form_debug_mode_form %}
                {{ form_widget(debugModeForm) }}
              {% endblock %}
            </div>
          </div>
          <div class="card-footer">
            <div class="d-flex justify-content-end">
              <button class="btn btn-primary">{{ 'Save'|trans({}, 'Admin.Actions') }}</button>
            </div>
          </div>
        </div>
      </div>
    {% endblock %}

    {% block perfs_form_optional_features %}
      <div class="col-xl-10">
        <div class="card" id="optional_features">
          <h3 class="card-header">
            <i class="material-icons">extension</i> {{ 'Optional features'|trans }}
          </h3>
          <div class="card-block row">
            <div class="card-text">

              <div class="row">
                <div class="col">
                  {{ ps.infotip('Some features can be disabled in order to improve performance.'|trans({}, 'Admin.Advparameters.Help')) }}
                </div>
              </div>

              {% block perfs_form_optional_features_form %}
                {{ form_widget(optionalFeaturesForm) }}
              {% endblock %}
            </div>
          </div>
          <div class="card-footer">
            <div class="d-flex justify-content-end">
              <button class="btn btn-primary">{{ 'Save'|trans({}, 'Admin.Actions') }}</button>
            </div>
          </div>
        </div>
      </div>
    {% endblock %}

    {% block perfs_form_ccc %}
      <div class="col-xl-10">
        <div class="card">
          <h3 class="card-header">
            <i class="material-icons">zoom_out_map</i> {{ 'CCC (Combine, Compress and Cache)'|trans }}
          </h3>
          <div class="card-block row">
            <div class="card-text">
              <div class="row">
                <div class="col">
                  {{ ps.infotip('CCC allows you to reduce the loading time of your page. With these settings you will gain performance without even touching the code of your theme. Make sure, however, that your theme is compatible with PrestaShop 1.4+. Otherwise, CCC will cause problems.'|trans({}, 'Admin.Advparameters.Help')) }}
                </div>
              </div>

              {% block perfs_form_ccc_form %}
                {{ form_widget(combineCompressCacheForm) }}
              {% endblock %}
            </div>
          </div>
          <div class="card-footer">
            <div class="d-flex justify-content-end">
              <button class="btn btn-primary">{{ 'Save'|trans({}, 'Admin.Actions') }}</button>
            </div>
          </div>
        </div>
      </div>
    {% endblock %}

    {% block perfs_form_media_servers %}
      <div class="col-xl-10">
        <div class="card">
          <h3 class="card-header">
            <i class="material-icons">link</i> {{ 'Media servers (use only with CCC)'|trans }}
          </h3>
          <div class="card-block row">
            <div class="card-text">
              <div class="row">
                <div class="col">
                  {{ ps.infotip('You must enter another domain, or subdomain, in order to use cookieless static content.'|trans({}, 'Admin.Advparameters.Feature')) }}
                </div>
              </div>

              {% block perfs_form_media_servers_form %}
                {{ form_widget(mediaServersForm) }}
              {% endblock %}
            </div>
          </div>
          <div class="card-footer">
            <div class="d-flex justify-content-end">
              <button class="btn btn-primary">{{ 'Save'|trans({}, 'Admin.Actions') }}</button>
            </div>
          </div>
        </div>
      </div>
    {% endblock %}

    {% block perfs_form_caching %}
      <div class="col-xl-10">
        <div class="card">
          <h3 class="card-header">
            <i class="material-icons">link</i> {{ 'Caching'|trans }}
          </h3>
          <div class="card-block row">
            <div class="card-text">
              {% block perfs_form_caching_form %}
                {{ form_widget(cachingForm) }}
              {% endblock %}

              {{ include('@AdvancedParameters/memcache_servers.html.twig', {'form': memcacheForm}) }}
            </div>
          </div>
          <div class="card-footer">
            <div class="d-flex justify-content-end">
              <button class="btn btn-primary">{{ 'Save'|trans({}, 'Admin.Actions') }}</button>
            </div>
          </div>
        </div>
      </div>
    {% endblock %}
  </div>
  {{ form_end(form) }}
{% endblock %}

{% block javascripts %}
  {{ parent() }}
  <script src="{{ asset('themes/default/js/bundle/admin_parameters/performancePage.js') }}"></script>
  <script>
    var configuration = {
      'addServerUrl': '{{ url('admin_servers_add')|e('js') }}',
      'removeServerUrl': '{{ url('admin_servers_delete')|e('js') }}',
      'testServerUrl': '{{ url('admin_servers_test')|e('js') }}'
    };
    var app = new PerformancePage(
      configuration.addServerUrl,
      configuration.removeServerUrl,
      configuration.testServerUrl
    );

    window.addEventListener('load', function() {
      var addServerBtn = document.getElementById('add-server-btn');
      var testServerBtn = document.getElementById('test-server-btn');

      addServerBtn.addEventListener('click', function(event) {
        event.preventDefault();
        app.addServer();
      });

      testServerBtn.addEventListener('click', function(event) {
        event.preventDefault();
        app.testServer();
      });
    });
  </script>

  <script src="{{ asset('themes/default/js/bundle/admin_parameters/performancePageUI.js') }}"></script>
{% endblock %}
